#!/bin/bash
read -p "请输入外网Ip:" NEW_IP

if [ -f "/home/backIp" ]; then
  OLD_IP=$(cat backIp)
  sed -i "s/${OLD_IP}/${NEW_IP}/g" /home/root/assist_dldl/config/assist.properties
  sed -i "s/${OLD_IP}/${NEW_IP}/g" /home/root/center/wow-server-center/config/game.properties
  sed -i "s/${OLD_IP}/${NEW_IP}/g" /home/root/wow-server-dldl_1/config/game.properties
  sed -i "s/${OLD_IP}/${NEW_IP}/g" /home/root/wow-assist/server_cfg/app_server/dldl/game.properties
  sed -i "s/${OLD_IP}/${NEW_IP}/g" /home/root/wow-assist/server_cfg/app_server/dldl_1/game.properties
  sed -i "s/${OLD_IP}/${NEW_IP}/g" /home/root/wow-assist/server_cfg/fight_server/dldl_center/game.properties
  sed -i "s/${OLD_IP}/${NEW_IP}/g" /home/root/wow-server/config/game.properties
  sed -i "s/${OLD_IP}/${NEW_IP}/g" /home/sql/assist_dldl.sql

  echo "========================================================"
  echo "UPDATE assist_dldl.server_config SET srv_host='${NEW_IP}' WHERE (id='1');
  UPDATE assist_dldl.fight_server SET srv_host='http://${NEW_IP}/' WHERE (id='1');
  UPDATE assist_dldl.game_zone_open SET server_url='${NEW_IP}' WHERE (id='8');FLUSH  PRIVILEGES;" >edit_ip.sql
  mysql -uroot -proot1234 <edit_ip.sql
  echo "========================================================"
  echo "修改服务端Ip成功,已把IP: ${OLD_IP} 修改为 ${NEW_IP}"
else
  sed -i "s/192.168.2.208/${NEW_IP}/g" /home/root/assist_dldl/config/assist.properties
  sed -i "s/192.168.2.208/${NEW_IP}/g" /home/root/center/wow-server-center/config/game.properties
  sed -i "s/192.168.2.208/${NEW_IP}/g" /home/root/wow-server-dldl_1/config/game.properties
  sed -i "s/192.168.2.208/${NEW_IP}/g" /home/root/wow-assist/server_cfg/app_server/dldl/game.properties
  sed -i "s/192.168.2.208/${NEW_IP}/g" /home/root/wow-assist/server_cfg/app_server/dldl_1/game.properties
  sed -i "s/192.168.2.208/${NEW_IP}/g" /home/root/wow-assist/server_cfg/fight_server/dldl_center/game.properties
  sed -i "s/192.168.2.208/${NEW_IP}/g" /home/root/wow-server/config/game.properties
  echo "========================================================"
  echo "UPDATE assist_dldl.server_config SET srv_host='${NEW_IP}' WHERE (id='1');
  UPDATE assist_dldl.fight_server SET srv_host='http://${NEW_IP}/' WHERE (id='1');
  UPDATE assist_dldl.game_zone_open SET server_url='${NEW_IP}' WHERE (id='8');FLUSH  PRIVILEGES;" >edit_ip.sql
  mysql -uroot -proot1234 <edit_ip.sql
  echo "========================================================"
  echo "修改服务端Ip成功,已把IP：192.168.2.208 修改为 ${NEW_IP}"
fi
echo "${NEW_IP}" >backIp
